package com.yi.zsb.handler;

import java.util.List;

import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;

import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor;
import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
import org.apache.cxf.databinding.DataBinding;
import org.apache.cxf.headers.Header;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.jaxb.JAXBDataBinding;
import org.apache.cxf.phase.Phase;

public class HeaderInterceptor extends AbstractSoapInterceptor {

	public HeaderInterceptor() {
		super(Phase.WRITE);
        addAfter(ReadHeadersInterceptor.class.getName());
        addAfter(EndpointSelectionInterceptor.class.getName());
        		
	}

	@Override
	public void handleMessage(SoapMessage message) throws Fault {
		try {
			List<Header> list = message.getHeaders();
			QName qname = new QName("http://ws.service.yi.com/" , "lenceInfo" , "ns");
			DataBinding dataBing = new JAXBDataBinding(String.class);
			Header header = new Header(qname , "admin" , dataBing);
			list.add(header);
		} catch (JAXBException e) {
			e.printStackTrace();
		}

	}

}
